package com.forusers.dyntyp.client;

import org.adamtacy.client.ui.NEffectPanel;
import org.adamtacy.client.ui.effects.impl.Fade;
import org.adamtacy.client.ui.effects.transitionsphysics.EaseInTransitionPhysics;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

public class RsvpEffect extends EffectBase {
	private NEffectPanel effPanel = new NEffectPanel();
	private Label newText;
	public void addWord(String word) {
		words.add(word);
	}
	
	public void setup() {
		RootPanel.get("panel").add(table);
		table.setWidth("100%");
		table.setHeight("100%");
		
		newText = new Label("");
		newText.addStyleName("centerText");
		effPanel.add(newText);
		index = 0;
		fadeText(words.get(index));
		table.setWidget(0, 0, effPanel);
	
        table.setWidget(1, 0, prevButton);
        prevButton.addClickHandler(new ClickHandler() {  
            public void onClick(final ClickEvent event) {  
            	prev();
            }
        });
        table.setWidget(1, 1, nextButton);
        nextButton.addClickHandler(new ClickHandler() {  
            public void onClick(final ClickEvent event) {  
            	next();
            }
        });
        table.getFlexCellFormatter().setColSpan(0, 0, 4);
        table.setHTML(1, 2, "&nbsp;");
        table.setHTML(1, 3, "&nbsp;");
        
        table.addClickHandler(new ArrowClickHandler());
        nextButton.addClickHandler(new ArrowClickHandler());
        index = -1;
		next();
	}
	
	public void applyEffect() {
		fadeText(words.get(index));
	}
	
	void fadeText(String text) {
		newText.setText(text);
		Fade fade = new Fade();
		fade.setDuration(1);
		effPanel.addEffect(fade);
		effPanel.setEffectsTransitionType(new EaseInTransitionPhysics());  
		effPanel.playEffects(1.0, 0.0);
	}
}
